home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / pmpsrc11.zip / REMOTE.C < prev    next >
Text File  |  1991-07-30  |  4KB  |  215 lines

  1. /*
  2.     remote.c -- Remote commands (not finished)
  3.  
  4.   Poor Man's Packet (PMP)
  5.   Copyright (c) 1991 by Andrew C. Payne    All Rights Reserved.
  6.  
  7.   Permission to use, copy, modify, and distribute this software and its
  8.   documentation without fee for NON-COMMERCIAL AMATEUR RADIO USE ONLY is hereby
  9.   granted, provided that the above copyright notice appear in all copies.
  10.   The author makes no representations about the suitability of this software
  11.   for any purpose.  It is provided "as is" without express or implied warranty.
  12.  
  13.     Andrew C. Payne
  14.     04/11/90
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <alloc.h>
  21. #include <mem.h>
  22. #include <string.h>
  23.  
  24. #include <dos.h>
  25. #include <dir.h>
  26. #include <alloc.h>
  27. #include "pmp.h"
  28.  
  29. #ifdef REMOTE
  30.  
  31. /* ----- Command dispatch tables ----- */
  32.  
  33. static int    doversion(char *s), dotime(char *s), dodir(char *s),
  34.         dobye(char *s), dotype(char *s), dohelp(char *s),
  35.         doinfo(char *s);
  36.  
  37. struct param_cmd rcmds[] = {
  38.     { "version",    doversion },
  39.     { "time",    dotime },
  40.     { "date",    dotime },
  41.     { "dir",    dodir },
  42.     { "bye",    dobye },
  43.     { "type",    dotype },
  44.     { "help",    dohelp },
  45.     { "info",    doinfo },
  46.     { NULL,        NULL } };
  47.  
  48. /* ----- Local subroutines ----- */
  49.  
  50. /* lprintf(format, ....)
  51.     Does a 'printf' across the currently connected link.  Items are
  52.     also echoed to the local screen.
  53. */
  54. static void lprintf(char *format, ...)
  55. {
  56.     va_list    argptr;
  57.     char    s[256];
  58.  
  59.     va_start(argptr, format);
  60.     vsprintf(s, format, argptr);
  61.     va_end(argptr);
  62.  
  63. /* send it across the link and show it on the screen */
  64.     LinkSend(s, strlen(s));
  65. /*    uprintf(BrightAttr, s); */
  66. }
  67.  
  68. /* ----- Remote command processing ----- */
  69.  
  70. /* command(s)
  71.     Given the command string (less any prefix), processes
  72.     the command.
  73. */
  74. void command(char *s)
  75. {
  76.     trim(s);
  77.     if(dispatch(s, rcmds) == FAIL)
  78.         lprintf(">> Invalid command.\n");
  79. }
  80.  
  81. /* doversion(char *s)
  82.     Shows the current version number.
  83. */
  84. static int doversion(char *s)
  85. {
  86.     lprintf(">> PMP Version %s (compiled %s)  by N8KEI\n",VERSION,__DATE__);
  87. }
  88.  
  89. /* dotime(char *s)
  90.     Shows the current date and time.
  91. */
  92. static int dotime(char *s)
  93. {
  94.     time_t    t;
  95.  
  96.     time(&t);
  97.     lprintf(">> %s",ctime(&t));
  98. }
  99.  
  100. /* dodir(char *s)
  101.     Shows the directory of the current disk.
  102. */
  103. static int dodir(char *s)
  104. {
  105.     struct ffblk    ffblk;
  106.     int    done;
  107.     char    *cwd;
  108.     struct dfree    dtable;
  109.     long    f;
  110.     int    count;
  111.  
  112. /* show current working directory */
  113.     cwd = getcwd(NULL, 80);
  114.     lprintf(">> Directory of %s\n",cwd);
  115.     free(cwd);
  116.  
  117.     s = sob(s);
  118.     if(!*s)
  119.         s = "*.*";
  120.  
  121. /* show files in directory */
  122.     done = findfirst(s, &ffblk, 0);
  123.     count = 0;
  124.     while(!done) {
  125.         lprintf("  %-14s  ",ffblk.ff_name);
  126.         if((++count % 4) == 0)
  127.             lprintf("\n");
  128.         done = findnext(&ffblk);
  129.     }
  130.     if(count % 4)
  131.         lprintf("\n");
  132.  
  133. /* show free space on drive */
  134.     getdfree(0, &dtable);
  135.     f = (long)dtable.df_avail * (long)dtable.df_bsec * (long)dtable.df_sclus;
  136.     lprintf(">> %ld bytes free on disk.\n",f);
  137. }
  138.  
  139. /* dobye(s)
  140.     Disconnect.
  141. */
  142. static int dobye(char *s)
  143. {
  144.     AX25_Close();
  145. }
  146.  
  147. /* dotype(char *s)
  148.     Types a file.
  149. */
  150. static int dotype(char *s)
  151. {
  152.     FILE    *outfile;
  153.     char    buf[1024];
  154.     int    len;
  155.  
  156. /* open the file */
  157.     if((outfile = fopen(s,"r")) == NULL) {
  158.         lprintf(">> Can't access file.\n");
  159.         return FALSE;
  160.     }
  161.  
  162. /* push the file across the link */
  163.     while(len = fread(buf, 1, 1024, outfile))
  164.         LinkSend(buf, len);
  165.  
  166.     fclose(outfile);
  167.     lprintf("\n>> EOF\n");
  168. }
  169.  
  170. /* dohelp(char *s)
  171.     Shows help file.
  172. */
  173. static int dohelp(char *s)
  174. {
  175.     FILE    *outfile;
  176.     char    buf[1024];
  177.     int    len;
  178.  
  179. /* open the file */
  180.     if((outfile = fopen("pmp.hlp","r")) == NULL) {
  181.         lprintf(">> Help not available.\n");
  182.         return FALSE;
  183.     }
  184.  
  185. /* push the file across the link */
  186.     while(len = fread(buf, 1, 1024, outfile))
  187.         LinkSend(buf, len);
  188.  
  189.     fclose(outfile);
  190. }
  191.  
  192. /* doinfo(char *s)
  193.     Shows info file.
  194. */
  195. static int doinfo(char *s)
  196. {
  197.     FILE    *outfile;
  198.     char    buf[1024];
  199.     int    len;
  200.  
  201. /* open the file */
  202.     if((outfile = fopen("pmp.inf","r")) == NULL) {
  203.         lprintf(">> Information not available.\n");
  204.         return FALSE;
  205.     }
  206.  
  207. /* push the file across the link */
  208.     while(len = fread(buf, 1, 1024, outfile))
  209.         LinkSend(buf, len);
  210.  
  211.     fclose(outfile);
  212. }
  213.  
  214. #endif    /* REMOTE */
  215.